using System;
using System.IO;
using System.Xml;

using Atomic.Vasp.Options;

namespace Atomic.Vasp.LinearResponse
{
	/// <summary>
	/// Executes the VASP density perturbation functional theory implementation (IBRION=5,6,7,8) to compute second order
	/// derivatives of the energy.
	/// http://cms.mpi.univie.ac.at/vasp/vasp/IBRION_7_IBRION_8.html
	/// </summary>
	[Serializable]
	public class VaspLinearResponseProblem : VaspProblem
	{
		public VaspLinearResponseProblem()
		{
			// Use DFPT by default.
			LinearResponseOption = new LinearResponsePerturbation();
		}

		public VaspLinearResponseResult RunLinearResponse()
		{
			return (VaspLinearResponseResult)Run();
		}

		protected override void Prepare(DirectoryInfo directory, VaspOptionCollection options)
		{
			base.Prepare(directory, options);

			if (LinearResponseOption == null)
			{
				throw new Exception();
			}

			// Add the linear response option to the usual option loop.
			options.Add(LinearResponseOption);
		}

		protected override VaspResult Finalize(DirectoryInfo directory)
		{
			return new VaspLinearResponseResult(directory);
		}

		public VaspLinearResponseOption LinearResponseOption
		{
			get;
			set;
		}
	}
}
